package com.example.provider.qiniuyun;

import java.io.Serializable;

public class APIResult<T> implements Serializable {
    private static final long serialVersionUID = -2982140134881098235L;
    private boolean success = false;
    private String code;
    private String message;
    private T data;

    public APIResult() {
    }

    public APIResult(boolean success, T data, String code, String message) {
        this.success = success;
        this.data = data;
        this.code = code;
        this.message = message;
    }

    public static <T> APIResult<T> create() {
        return new APIResult();
    }

    public static <T> APIResult<T> create(T data) {
        APIResult<T> result = create();
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

    public static <T> APIResult<T> create(T data, String code, String message) {
        APIResult<T> result = create();
        result.setSuccess(true);
        result.setData(data);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> APIResult<T> create(T data, boolean isSuccess, String code, String message) {
        APIResult<T> result = create();
        result.setSuccess(isSuccess);
        result.setData(data);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> APIResult<T> create(String code, String message) {
        APIResult<T> result = create();
        result.setSuccess(false);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> APIResult<T> create(ErrorCodeEnum errorCodeEnum) {
        APIResult<T> result = create();
        result.setSuccess(false);
        result.setCode(errorCodeEnum.getErrCode());
        result.setMessage(errorCodeEnum.getErrMsg());
        return result;
    }

    public boolean isSuccess() {
        return this.success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
